#include <bits/stdc++.h>
using namespace std;

int main() {
  int weight, base;
  cin >> base >> weight; // 输入基数和权重
  while (weight > 1) {
    int remainder = weight % base; // 计算余数
    if (remainder == base - 1) {
      remainder = -1; // 特殊情况处理
    }
    // 检查余数是否为有效值
    if (remainder == 1 || remainder == 0 || remainder == -1) {
      weight = (weight - remainder) / base; // 更新权重
    } else {
      cout << "No"; // 输出结果
      return 0;
    }
  }
  cout << "Yes"; // 输出结果
  return 0;
}